<?

/**
* local collection functions of tocmenu_611
*
* @author Adesanto Asman
* @version 1.0
* @license Free
* @copyright Copyright (c)2007, Adesanto Asman
* @package CLHandlers
*
*/

/**
* @package CLHandlers
*
*/
class CLHandlers{

  /**
   * tansfer real mutation whs SN to tmp table
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $tmpJid
   * @param Composer  $SourceDb
   */
  function transRealMutWhsSnToTmp(&$Db,
                                   $jobId,
                                   $tmpJid,
                                  &$SourceDb){

    /**
     * transfer...
     */
    $query  = "INSERT INTO ".$SourceDb->fetchValue("srcDbTmpSubDtlSN")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbSubDtlSN")."
               WHERE  JOB_ID='".$jobId."' ";

    $Db->execQuery($query);

    $query  = "INSERT INTO ".$SourceDb->fetchValue("srcDbTmpSubDtlComposSN")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbSubDtlComposSN")."
               WHERE JOB_ID='".$jobId."' ";

    $Db->execQuery($query);

    /**
     * we reset tmp jobId
     * jobId --> tmpJid
     */
    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbTmpSubDtlSN")."
               SET JOB_ID='".$tmpJid."'
               WHERE  JOB_ID='".$jobId."' ";

    $Db->execQuery($query);

    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbTmpSubDtlComposSN")."
               SET JOB_ID='".$tmpJid."'
               WHERE  JOB_ID='".$jobId."' ";

    $Db->execQuery($query);
  }

  /**
   * tansfer tmp mutation whs SN to real table
   *
   * @param Database  $Db
   * @param string    $jobId
   * @param string    $tmpJid
   * @param Composer  $SourceDb
   */
  function transTmpMutWhsSnToReal(&$Db,
                                   $jobId,
                                   $tmpJid,
                                  &$SourceDb){

    /**
     * transfer...
     */
    $query  = "INSERT INTO ".$SourceDb->fetchValue("srcDbSubDtlSN")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbTmpSubDtlSN")."
               WHERE JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);

    $query  = "INSERT INTO ".$SourceDb->fetchValue("srcDbSubDtlComposSN")."
               SELECT *
               FROM ".$SourceDb->fetchValue("srcDbTmpSubDtlComposSN")."
               WHERE JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);

    /**
     * we set the Jobid
     * tmpJid --> jobId
     */
    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbSubDtlComposSN")."
               SET JOB_ID='".$jobId."'
               WHERE  JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);

    $query  = "UPDATE ".$SourceDb->fetchValue("srcDbTmpSubDtlComposSN")."
               SET JOB_ID='".$jobId."'
               WHERE  JOB_ID='".$tmpJid."' ";

    $Db->execQuery($query);
  }

  /**
   * insert into sub detail of mutation whs SN
   * not a composition or this is a parent model id
   *
   * @param Database  $Db
   * @param string    $values
   * @param string    $srcDb
   */
  function insToSubDtlSN($Db,
                         $values,
                         $srcDb){

    $query	= "INSERT INTO ".$srcDb."
               (JOB_ID,
                NO,
                MODEL_ID,
                SN)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }

  /**
   * insert into sub detail of composition SN
   *
   * @param Database  $Db
   * @param string    $values
   * @param string    $srcDb
   */
  function insToSubDtlComposSN($Db,
                               $values,
                               $srcDb){

    $query	= "INSERT INTO ".$srcDb."
               (JOB_ID,
                NO,
                PARENT_MODEL_ID,
                SRC_MODEL_ID,
                MODEL_ID,
                SN)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }

  /**
   * insert into header
   *
   * @param Database  $Db
   * @param string    $values
   * @param string    $srcDb
   */
  function insToHdr(&$Db,
                    &$values,
                     $srcDb){

    $query	= "INSERT INTO ".$srcDb."
               (JOB_ID,
                REFERENCE,
                TR_DATE,
                NO,
                FROM_WHS,
                TO_WHS,
                MODEL_ID,
                QTY,
                MEMO,
                STATUS)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }

  /**
   * insert into detail
   *
   * @param Database  $Db
   * @param string    $values
   * @param string    $srcDb
   */
  function insToDtl(&$Db,
                    &$values,
                     $srcDb){

    $query	= "INSERT INTO ".$srcDb."
               (JOB_ID,
                NO,
                SN)
               VALUES (".$values.")";

    $Db->execQuery($query);
  }
}

?>